<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<html>
<head>
  <title>互动通知</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <style>
    .notification-item {
      border-left: 3px solid transparent;
      transition: all 0.3s ease;
    }
    .notification-item.unread {
      border-left-color: var(--primary);
      background-color: rgba(91, 95, 255, 0.05);
    }
    .notification-item:hover {
      background-color: rgba(91, 95, 255, 0.1);
    }
    .notification-avatar {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      object-fit: cover;
    }
  </style>
</head>
<body>
<jsp:include page="../header.jsp"/>

<div class="container my-5">
  <div class="row">
    <div class="col-md-8 mx-auto">
      <div class="card">
        <div class="card-header bg-white d-flex justify-content-between align-items-center">
          <h5 class="mb-0">互动通知</h5>
          <a href="#" class="btn btn-sm btn-outline-primary">全部标记为已读</a>
        </div>
        <div class="card-body p-0">
          <c:choose>
            <c:when test="${not empty notifications}">
              <div class="list-group list-group-flush">
                <c:forEach items="${notifications}" var="notification">
                  <div class="list-group-item notification-item ${not notification.read ? 'unread' : ''}">
                    <div class="d-flex align-items-start">
                      <img src="${pageContext.request.contextPath}/${notification.senderAvatar}"
                           class="notification-avatar me-3" alt="用户头像">
                      <div class="flex-grow-1">
                        <div class="d-flex justify-content-between align-items-center mb-1">
                          <h6 class="mb-0">${notification.senderNickname}</h6>
                          <small class="text-muted">
                            <fmt:formatDate value="${notification.createdAt}" pattern="yyyy-MM-dd HH:mm"/>
                          </small>
                        </div>
                        <p class="mb-1">${notification.content}</p>
                        <c:if test="${notification.type == 'like'}">
                          <a href="${pageContext.request.contextPath}/post/detail?id=${notification.relatedId}"
                             class="btn btn-sm btn-outline-primary mt-1">查看日志</a>
                        </c:if>
                        <c:if test="${notification.type == 'comment' || notification.type == 'reply'}">
                          <a href="${pageContext.request.contextPath}/post/detail?id=${notification.relatedId}"
                             class="btn btn-sm btn-outline-primary mt-1">查看评论</a>
                        </c:if>
                      </div>
                    </div>
                  </div>
                </c:forEach>
              </div>
            </c:when>
            <c:otherwise>
              <div class="text-center py-5">
                <i class="fa fa-bell-slash-o fa-3x text-muted mb-3"></i>
                <p class="text-muted">暂无新通知</p>
              </div>
            </c:otherwise>
          </c:choose>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>